package com.yingluo.abacus.plantform.docs.app.example;

import com.yingluo.abacus.plantform.docs.app.example.vo.Man;
import com.yingluo.abacus.plantform.docs.app.example.vo.Person;
import com.yingluo.abacus.plantform.docs.app.example.vo.XmlActionResult;
import com.yingluo.abacus.plantform.docs.app.utils.DocsAppUtils;
import com.yingluo.abacus.plantform.utils.PlantformUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class DemoController {
    private final static String PATH= DocsAppUtils.MOUDLE_PATH +"/example/demo";
    private static final Logger logger = LoggerFactory.getLogger(DemoController.class);
    @RequestMapping(PlantformUtils.PROJECT_PATH+PATH+"/json")
    public  @ResponseBody
    Person json(){
        Person p1=new Person("bb",2);
        return p1;
    }

    @RequestMapping(PlantformUtils.PROJECT_PATH+PATH+"/xml/{name}")
    @ResponseBody
    public  XmlActionResult<Man>  xml(@PathVariable("name") String name ){
    	 XmlActionResult<Man> actionResult = new XmlActionResult<Man>();
         actionResult.setCode("123");
         actionResult.setMessage(name);
         Man person = new Man("xxxxx",1,32);

         actionResult.setData(person);
         return actionResult;
    }
    
    @RequestMapping(PlantformUtils.PROJECT_PATH+PATH+"/list")
    public String list(Model model){
        Person single=new Person("aa",1);
        List<Person> people=new ArrayList<Person>();
        Person p1=new Person("bb",2);
        Person p2=new Person("cc",3);
        Person p3=new Person("dd",4);
        people.add(p1);
        people.add(p2);
        people.add(p3);
        model.addAttribute("singlePerson",single);
        model.addAttribute("people",people);
		return PATH +"/list";
    }

//
//    @RequestMapping("fileUpload")
//    public String  fileUpload(@RequestParam("file") CommonsMultipartFile file) throws IOException {
//    	 return "/success";
//    }
    

   
}
